var app = getApp();
const apiHost = require('../../../common/api_host.js');
var utils = require('../../../utils/utils.js');
var httpJson=require('../../../utils/http_json.js');
Page({
  getuser:function(){
    var  url=`${apiHost.config.portalApiHost}/portal/user/update`;
   
    httpJson.post(url,{},res=>{
      if(res.data.errorCode==0){
        
        this.setData({
          userMsg:res.data.body
        })
        this.getgoodsList(0)
      }
    })
  },
  getgoodsList:function(pageNum){
    var  url=`${apiHost.config.portalApiHost}/portal/goodsinfo`;
   let data={
     pageNum,
     pageSize:10
   }
    httpJson.get(url,data,res=>{
      if(res.data.errorCode==0){
        let goodsList=res.data.body.rows;
          // goodsList.forEach((ele)=>{
          // console.log(this.data.userMsg)
          //   if(ele.grade<=this.data.userMsg.grade&&ele.exchangePoint<=this.data.userMsg.point){
          //     ele.canChange=true
          //   }else{
          //     ele.canChange=false
          //   }
          // })
        this.setData({
          goodsList
        })
      }
    })
  },
  change:function(e){
    var _this=this;
    let needpoint= app.E(e,'needpoint');
    let needgrade=app.E(e,'needgrade');
    let goodsId=app.E(e,'myid');
    let name=app.E(e,'name');

    if(needgrade<=this.data.userMsg.grade&&needpoint<=this.data.userMsg.point){
      this.setData({
        goodsId,name,needpoint,canChange:true
      })
    //  wx.navigateTo({
    //    url:'../addmsg/addmsg?id='+goodsId
    //  })
    }else{
      this.setData({
        canotChange:true
      })
      // wx.showModal({
      //   title: '提示',
      //   content: '你现在档案等级不够，快去努力升级吧,点击确定可查看升级攻略',
      //   success(res) {
      //     if (res.confirm) {
      //       _this.setData({
      //         showTip:true

      //       })
            
      //     } else if (res.cancel) {
      //       _this.setData({
      //         showTip:false

      //       })
          
      //     }
      //   }
      // })
    }



  },
  noshowtip:function(){
    this.setData({
      canotChange:false
    })
  },
  showtip:function(){
    this.setData({
      showTip:true,canotChange:false
    })
  },
  notwant:function(){
    this.setData({
      canChange:false
    })
  },
  want:function(){
    this.setData({
      canChange:false
    })
    wx.navigateTo({
      url:'../addmsg/addmsg?id='+this.data.goodsId
    })
  },
  closeTip:function(){
    this.setData({
      showTip:false
    })
  },
  showrecord:function(){
    wx.navigateTo({
      url:"../record/record"
    })
  },
  changename:function(){
    wx.navigateTo({
      url:'/pages/register/register?myid=3'
    })

  },
  /**
   * 页面的初始数据
   */
  data: {
    showTip:false,
    gifts:[
      {dangan:1,suipian:11,img:'http://img18.3lian.com/d/file/201709/18/d1846c73dfcd427259aad2165cafc996.jpg'},
      {dangan:1,suipian:11,img:'http://image.biaobaiju.com/uploads/20180920/21/1537451442-bzkRKBQIVG.jpg'},
      {dangan:1,suipian:11,img:'http://img18.3lian.com/d/file/201709/18/d1846c73dfcd427259aad2165cafc996.jpg'},
      {dangan:1,suipian:11,img:'http://image.biaobaiju.com/uploads/20180920/21/1537451442-bzkRKBQIVG.jpg'},
      {dangan:1,suipian:11,img:'http://img18.3lian.com/d/file/201709/18/d1846c73dfcd427259aad2165cafc996.jpg'},
      {dangan:1,suipian:11,img:'http://image.biaobaiju.com/uploads/20180920/21/1537451442-bzkRKBQIVG.jpg'},
      {dangan:1,suipian:11,img:'http://img18.3lian.com/d/file/201709/18/d1846c73dfcd427259aad2165cafc996.jpg'},
      {dangan:1,suipian:11,img:'http://image.biaobaiju.com/uploads/20180920/21/1537451442-bzkRKBQIVG.jpg'},
    ]

  },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      // if(options.fromchange){
      //   this.getuser()


      // }
      console.log("eafsf")
      this.getuser()
     
  
  
    },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage(res) {
    app.share()
    if (res.from === 'button') {
      var content=res.target.dataset.content
     
      if(content.length>50){
        content=content.substr(0,50)+'...'
      }
      var title=content
    }
    if(res.from === 'menu'){
      var imageUrl="/images/index/reply/reply.png";
      var title='我正在惊人院，邀请你来……'
    }
    return {
      title,
      imageUrl
      
    }
  }
})